package com.app.view.component.hall.item 
{
	import com.peachcastle.tools.Assert;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.ui.Mouse;
	import org.component.events.ListEvent;
	import org.component.interfaces.IListItemData;
	import org.component.item.ListItem;
	import com.peachcastle.events.HallEvent;
	import com.app.model.data.HallListItemData;

	public class HallListItem extends ListItem
	{
		private var _txt_id:TextField = null;
		private var _txt_name:TextField = null;
		private var _txt_banker:TextField = null;
		//移上背景 zzj
		private var _txt_background:MovieClip = null;
		
		private var _txt_minPour:TextField = null;
		private var _txt_basechip:TextField = null;
		
		private var _btn_room:SimpleButton = null;
		
		private var _connection:Array = ["id", "name", "minPour"];
		
		private var _counts:Array = null;
		public function HallListItem(ui:MovieClip = null) 
		{
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			
			_txt_background = assest["_txt_background"];
			
			
			for each(var str:String in _connection)
			{
				//断言
				Assert.hasNot(assest, "txt_"+str, 'HallListItem');
				
				this["_txt_" + str] = assest["txt_"+str];
				this["_txt_" + str].mouseEnabled = false;
			}
			
			_counts = [];
			for (var i:int = 0; i < 8; i++)
			{
				//断言
				Assert.hasNot(assest, "count" + i, 'HallListItem');
				
				var mc:MovieClip = assest["count" + i];
				mc.mouseEnabled = false;
				_counts[_counts.length] = mc;
			}
			assest.buttonMode = true;
			assest.mouseChildren = false;	//如果要收到鼠标双击的事件，就必须要加这个
		}
		
		override protected function configEventListeners():void 
		{
			super.configEventListeners();
			
			//移上背景变化
			
			assest.doubleClickEnabled = true;
			assest.addEventListener(MouseEvent.ROLL_OVER, onAssestOver);
			assest.addEventListener(MouseEvent.ROLL_OUT, onAssestOut);
			assest.addEventListener(MouseEvent.CLICK, onAssestClick);
			assest.addEventListener(MouseEvent.DOUBLE_CLICK, onAssestDoubleClick);
		}
		
		
		//结束
		private function onAssestOver(event:MouseEvent):void
		{
			if (select) return;
			assest.gotoAndStop(2);
			_txt_background.gotoAndStop(2);
		}
		private function onAssestOut(event:MouseEvent):void
		{
			if (select) return;
			assest.gotoAndStop(1);
			_txt_background.gotoAndStop(1);
		}
		
		private function onRoomClick(event:MouseEvent):void
		{
			event.stopPropagation();
			
			var evt:ListEvent = new ListEvent(ListEvent.LIST_SELECT_ROOM);
			evt.item = this;
			_subject.dispatchEvent(evt);
			evt = null;
		}
		
		private function onAssestClick(event:MouseEvent):void
		{
			_txt_background.gotoAndStop(1);
			event.stopPropagation();
			_subject.selectItem = this;
			var evt:ListEvent = new ListEvent(ListEvent.LIST_SELECT_ROOM);
			evt.item = this;
			_subject.dispatchEvent(evt);
			evt = null;
			_txt_background.gotoAndStop(3);
		}
		
		private function onAssestDoubleClick(event:MouseEvent):void
		{
			var evt:ListEvent = new ListEvent(ListEvent.LIST_SELECT);
			evt.item = this;
			_subject.dispatchEvent(evt);
			evt = null;
		}
		override public function update(data:IListItemData = null):void 
		{
			super.update(data);

			_txt_id.text = HallListItemData(data).roomid.toString();
			_txt_name.text = HallListItemData(data).name;
			_txt_minPour.text = HallListItemData(data).minPour.toString();
			
			var count:int = HallListItemData(data).currMember;

			for (var i:int = 0; i < _counts.length; i++)
			{
				if (i < count)
				{
					_counts[i].gotoAndStop(2);
				}else
				{
					_counts[i].gotoAndStop(1);
				}
			}	
			
		}
		override public function get select():Boolean { return super.select; }
		
		override public function set select(value:Boolean):void 
		{
			super.select = value;
			
			if (value)
			{
				assest.gotoAndStop(3);
			}else
			{
				assest.gotoAndStop(1);
			}
		}		
	}

}